<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String ip = "http://localhost:8080";
/* String ip = "https://zy.renyibao.com"; */
String patient_blhm = request.getParameter("patient_blhm");
String patient_name = request.getParameter("patient_name");
String hosid = request.getParameter("hosid");
String userid = request.getParameter("userid");
String token = request.getParameter("token");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
	<script src="<%=ip %>/doctor/plug_in/js/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="<%=ip %>/doctor/plug_in/js/mootools-core.js"></script>
    <style>
		.alWindow {
		       display: none; 
		       position: fixed; 
		       top: 25%; 
		       left: 25%; 
		       width: 35%; 
		       height: 60%; 
		       padding: 20px; 
		       border: 3px solid #ccc; 
		       background-color: white;
		       z-index:2; 
		       overflow: auto; 
		   }
		   .albackGround {
		       display: none; 
		       position: absolute; 
		       top: 0%; 
		       left: 0%; 
		       width: 100%; 
		       height: 1100px; 
		       background-color: black; 
		       z-index:1; 
		       -moz-opacity: 0.8; 
		       opacity:.80; 
		       filter: alpha(opacity=88);
		   }
		   #x:hover {cursor: pointer;color: rgb(55,198,192);}
	</style>

  </head>
  
  <body>
    成功了！！
	<div id="QRcodeWindow" class="alWindow">
	    <label id="x" style="position: absolute;top:2px;left: 95%;font-size: 25px;">x</label>
	    <form>
	        <div id="qrcode">
	        	
	        </div>
	
	    </form>
	</div>
	<div id="QRcodebackGround" class="albackGround"></div>
  </body>
	<script type="text/javascript">
	var url = '<%=ip %>/doctor/AppMainServlet.ap';
	var ip = '<%=ip %>';
	var patient_blhm = '<%=patient_blhm %>';
	var patient_name = '<%=patient_name %>';
	var hosid = '<%=hosid %>';
	var userid = '<%=userid %>';
	var token = '<%=token %>';
	
	window.onload = function(){
	    function proxy () {
	      window.addEventListener('storage', storageHandler, false); //localStorage or sessionStorage
	
	      function storageHandler (e) {
	        console.log(e.key);
	        if (e.key === '__storageProxy__') {
	          var url = window.localStorage.getItem('__storageProxy__');
	          url && window.open(url);
	          window.localStorage.setItem('__storageProxy__', ''); //fired storage event again
	        }
	      }
	    }
	
	    proxy();
  };
	
	$(function(){
		Qrcode();
	});
		//弹出二维码框
		function Qrcode(){
			getWxbindQRcode();
			
			$("#QRcodeWindow").slideDown(300);
        	$("#QRcodebackGround").show();
        	InterQrcodeRota = setInterval("listenQrcode()", 1000);
		}
		
		//监听二维码扫码绑定
		var listenQrcode = function(){
			var tn = "F27.APP.11.12";
			var param = "\{\"patientno\"\:\""+patient_blhm+"\"\}";
			var success = function(data){
				var item = eval('('+data+')').DATAOBJ.DATA;
				console.log(item);
				if(item!=null&&item.length>0){
	            	clearInterval(InterQrcodeRota);
					$("#QRcodeWindow").slideUp(300);
	            	$("#QRcodebackGround").hide();
	            	alert("提示","绑定微信用户成功！",function(){
	            		getWxUnbindPatlistY();
	            	});
				}
			};
			myRequest(url,tn,param,success);
		};
		
		//获取患者绑定二维码
		function getWxbindQRcode(){
			var tn = "F27.APP.11.08";
			var param = "\{\"hosid\":\""+hosid+"\",\"userid\":\""+userid+"\",\"patient_blhm\":\""+patient_blhm+"\",\"patient_name\":\""+patient_name+"\",\"rowsperpage\":\"200\",\"page\":\"1\",\"ordercolumn\":\"cre_time\",\"ordertype\":\"desc\"}";
			console.log("param:"+param);
			var success = function(data){
				var item = eval('('+data+')').DATAOBJ.DATA;
				console.log(item);
				var con = "<div><img style=\"height\:300px\;\" src=\""+item[0].QRURL+"\"></img></div><div><span>请您尽快扫码绑定微信</span><a title=\""+item[0].PATIENT_NAME+","+item[0].PATIENT_BLHM+"\" id=\"QRcode\">刷新</a></div>";
				console.log(con);
				$("#qrcode").html(con);
			};
			myRequest(url,tn,param,success);
		}
		
		//悬浮框
		  $(document).ready(function(){
	
	          $("#x").click(function(){
	              $("#QRcodeWindow").slideUp(300);
	              $("#QRcodebackGround").hide();
	              getWxUnbindPatlistY();
	              clearInterval(InterDoctorRota);
	          });
	
	      });
		
	    //执行本地请求
		function myRequest(url,tn,param,success){
				
				var message = "{\"OTRequest\":  {\"VERSION\":\"1.0\",   \"TN\":\""+
							tn+"\",   \"CLIENTID\":\"YLAPP\",   \"RYBID\":\"WEBPLUS_PAWJ\", \"TOKEN\":\""+token+"\" , \"DATA\":"+
							param+"}}";//WEBPLUS_PAWJ   rybid 等程序调好后填入  常量
				if(ip.indexOf("localhost")>0){
					message = "{\"OTRequest\":  {\"VERSION\":\"1.0\",   \"TN\":\""+
							tn+"\",   \"CLIENTID\":\"YLAPP\",   \"RYBID\":\"\", \"TOKEN\":\""+token+"\" , \"DATA\":"+
							param+"}}";
				}
				console.log(message);
				
				var myRequest = new Request.HTML({
				
					url: url,   
				    
				    xhrFields: {  
				      withCredentials: true, // 设置运行跨域操作  
				    },  
						
					onRequest: function(){
						//console.log("正在请求...");
					},
					
					//成功的回调函数
					onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
		        		success(responseHTML);
					},
					
					//失败的回调函数. 404. 500. 以及返回JSON串success为false时执行
					onFailure: function(xhr){ //alert(2);
					   //alert(xhr.responseText);
					   console.log(xhr.responseText);
					}
				});
				
				//console.log(message);
				
				myRequest.send(message);
			};
	</script>
</html>
